package cn.htsyb.synergy.model;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.Accessors;

import java.io.Serializable;

/**
 * 
 * @author lakeside hubin_yuan.410@hotmail.com
 * @version V1.0.0
 * @since 1.0
 * @date 2022/5/11
 */
@Setter
@Getter
@Accessors(chain = true)
@NoArgsConstructor
@Schema(description = "接口响应")
public class ApiResult<T> implements Serializable {

    @Schema(name = "code", description = "状态码")
    protected Integer code = 200;
    @Schema(name = "message", description = "消息")
    protected String message;
    @Schema(name = "result", description = "结果")
    protected T result;

    public ApiResult(T result) {
        this.result = result;
    }

    public ApiResult(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    public ApiResult(Integer code, String message, T result) {
        this.code = code;
        this.message = message;
        this.result = result;
    }

    public static <T> ApiResult<T> instance() {
        return new ApiResult<T>();
    }

    public static <T> ApiResult<T> instance(T result) {
        return new ApiResult<>(result);
    }

    public static <T> ApiResult<T> instance(Integer code, String message) {
        return new ApiResult<T>(code, message);
    }

    public static <T> ApiResult<T> instance(Integer code, String message, T result) {
        return new ApiResult<T>(code, message, result);
    }
}
